<template>
	<view class="content">
		<u-navbar back-text="" 
		:leftIconColor="tksetting.titlecolor" 
		:bgColor="tksetting.color" 
		:titleStyle="{color:tksetting.titlecolor}" 
		:title="title"  
		:autoBack="true"  
		:placeholder="true">
		</u-navbar>
		<view class="" style="padding: 20rpx;">
			<view style="padding: 10rpx 0;">用户:{{tel}}</view>
			<u--form
				labelPosition="top"
				:model="model1"
				labelWidth	="200"
				:labelStyle="labelStyle"
				ref="form1"
			>
			
			<u-form-item
				label="请选择操作类型"
				prop="type"
				borderBottom
				ref="item1"
				:required="true"
			>
			
			  <u-radio-group
			    v-model="model1.type"
			    placement="column"
			    @change="groupChange"
			  >
			    <u-radio
			      :customStyle="{margin: '12px 0'}"
			      label="增加积分"
			      name="3"
			    >
			    </u-radio>
				<u-radio
				  :customStyle="{margin: '12px 0'}"
				  label="减少积分"
				  name="4"
				>
				</u-radio>
			  </u-radio-group>
				
			</u-form-item>
			
			<u-form-item
				label="积分数量"
				prop="num"
				borderBottom
				ref="item1"
				:required="true"
			>
			
			 <u--input
			    placeholder="请输入具体数量"
			    clearable
				type="digit"
			    v-model="model1.num"
			  ></u--input>
				
			</u-form-item>
			
			
			<u-form-item
				label="扣减备注"
				prop="moto"
				borderBottom
				ref="item1"
				:required="true"
			>
			
			<u--textarea v-model="model1.moto" placeholder="请输入具体扣减类型" ></u--textarea>
				
			</u-form-item>
			
			
			
			<u-button
				type="primary"
				text="提交"
				customStyle="margin-top: 50px"
				:color="tksetting.color"
				@click="submit"
			></u-button>	
			
			</u--form>
			
		</view>
	</view>
</template>
<script>
import {toast, clearStorageSync, setStorageSync, getStorageSync, useRouter} from '@/utils/utils.js'
import { mapState } from 'vuex';
export default {
	data() {
		return {
			title:"积分核销",
			tel:'',
			model1:{
				uid:47,
				type:'',
				num:'',
				moto:''
			},
			rules: {
				'type': {
					type: 'number',
					required: true,
					message: '请选择操作类型',
					trigger: ['blur', 'change']
				},
				'num': {
					type: 'number',
					min:1,
					required: true,
					message: '请输入扣减积分数量',
					trigger: ['blur', 'change']
				},
				'moto': {
					type: 'string',
					required: true,
					message: '请输入扣减事项',
					trigger: ['blur']
				}
			}
		}
	},
	onLoad(op) {
		const params = JSON.parse(decodeURIComponent(op.data));
		console.log(params)
		this.model1.uid  = params.uid
		this.init();
	},
	onShow() {
	},
	onReady() {
		this.$refs.form1.setRules(this.rules)
	},
	computed: {
		...mapState(['tksetting'])
	},
	methods: {
		groupChange(n) {
		       this.model1.type=n;
		},
		init(){
			this.$api.hexiao(this.model1).then(res=>{
				if(res.code==0){
					this.tel=res.data.tel
				}else{
					uni.showModal({
						  title: '提示',
						  showCancel:false,
						  content: res.msg,
						  success: (res) => {
							if (res.confirm) {
							   uni.navigateBack();
							}
						}
					});
				}
			})
		},
		async submit(){
			const _this=this;
			const yz=await  _this.$refs.form1.validate().then(res => {
				return true;
			}).catch(errors => {
				return false
			})
			
			if(yz){
				
				this.$api.hexiao2(this.model1).then(res=>{
					if(res.code==0){
						
						
						uni.showModal({
							  title: '提示',
							  cancelText:'返回',
							  confirmText:'继续操作',
							  content: res.msg,
							  success: (res) => {
								if (res.confirm) {
									this.model1.type=''
									this.model1.num=''
									this.model1.moto=''
								}else{
									uni.navigateBack();
								}
							}
						});
						
					}else{
						
						uni.showModal({
							  title: '提示',
							  content: res.msg,
							  success: (res) => {
								if (res.confirm) {
								   uni.navigateBack();
								}
							}
						});
						
					}
				})
				
				
			}
			
		}
	}
}
</script>
<style lang="scss" scoped>
	.content{}
</style>